/*
 * @Author: 杜二康 3224811364@qq.com
 * @Date: 2024-07-02 14:36:43
 * @LastEditors: 杜二康 3224811364@qq.com
 * @LastEditTime: 2024-07-10 11:36:25
 * @FilePath: \my-app\src\service\question.ts
 * @Description: 问卷接口
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */

import axios, { ResDataType } from "./ajax";

type SearchOption = {
  keyword: string;
  isDeleted: boolean;
  isStar: boolean;
  page: number;
  pageSize: number;
};

export async function getQuestionService(id: string): Promise<ResDataType> {
  const url = `/api/question/${id}`;
  return (await axios.get(url)) as ResDataType;
}

export async function createQuestionService(): Promise<ResDataType> {
  const url = "/api/question";
  return (await axios.post(url)) as ResDataType;
}

export async function getQuestionListService(
  opt: Partial<SearchOption> = {}
): Promise<ResDataType> {
  const url = "/api/question";
  return (await axios.get(url, { params: opt })) as ResDataType;
}

export async function updateQuestionService(
  id: string,
  opt: {
    [key: string]: any;
  }
): Promise<ResDataType> {
  const url = `/api/question/${id}`;
  return (await axios.patch(url, { params: opt })) as ResDataType;
}

export async function duplicateQuestionService(
  id: string
): Promise<ResDataType> {
  const url = `/api/question/duplicate/${id}`;
  return (await axios.post(url)) as ResDataType;
}

export async function deleteQuestionService(
  ids: string[]
): Promise<ResDataType> {
  const url = "/api/question";
  return (await axios.delete(url, { params: ids })) as ResDataType;
}
